
//
//  TableViewHeaderFooterView.m
//  OAProject
//
//  Created by yhj on 2017/2/22.
//  Copyright © 2017年 cdnunion. All rights reserved.
//

#import "TableViewHeaderFooterView.h"

@interface TableViewHeaderFooterView()

@end

@implementation TableViewHeaderFooterView

+ (instancetype)headerView:(UITableView *)tableView
{
    static NSString *identifier=@"header";
    TableViewHeaderFooterView *headerView=(TableViewHeaderFooterView *)[tableView dequeueReusableCellWithIdentifier:identifier];
    if (!headerView){
        headerView=[[TableViewHeaderFooterView alloc] initWithReuseIdentifier:identifier];
    }

    return headerView;
}

-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self=[super initWithReuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.nameLabel.font=Font_Number(14);

        self.topLine.hidden=NO;

        self.bottomLine.hidden=NO;

        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapEvent)];
        [self addGestureRecognizer:tap];

    }
    return self;
}

// signStateIcon
-(UIImageView *)signStateIcon
{
    if (!_signStateIcon) {
        _signStateIcon=[UIImageView new];
        _signStateIcon.backgroundColor=[UIColor yellowColor];
        [self.contentView addSubview:_signStateIcon];
        // 圆角和边框
        ViewBorderRadius(_signStateIcon,kmargin*3/2,kmargin/kmargin,ClearColor);

        [_signStateIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kmargin*2);
            make.centerY.mas_equalTo(self);
            make.size.mas_equalTo(CGSizeMake(kmargin*3,kmargin*3));
        }];
    }
    return _signStateIcon;
}

// nameLabel
- (UILabel *)nameLabel
{

    if (!_nameLabel) {
        _nameLabel=[self getLabelWithText:@"上班签到" font:Font_Number(18) textColor:[UIColor blackColor] textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.contentView addSubview:_nameLabel];
        [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.signStateIcon.mas_right).offset(kmargin);
            make.centerY.mas_equalTo(self);
        }];
    }
    return _nameLabel;
}

// topLine
-(UIView *)topLine
{
    if (!_topLine) {
        _topLine=[UIView new];
        [self.contentView addSubview:self.topLine];
        _topLine.backgroundColor=Color999999;
        [_topLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.signStateIcon.mas_centerX);
            make.top.mas_equalTo(0);
            make.width.mas_equalTo(1);
            make.bottom.mas_equalTo(self.signStateIcon.mas_top);
        }];
    }
    return _topLine;
}


// bottomLine
-(UIView *)bottomLine
{
    if (!_bottomLine) {
        _bottomLine=[UIView new];
        [self.contentView addSubview:self.bottomLine];
        _bottomLine.backgroundColor=Color999999;
        [_bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.signStateIcon.mas_centerX);
            make.top.mas_equalTo(self.signStateIcon.mas_bottom);
            make.width.mas_equalTo(1);
            make.bottom.mas_equalTo(0);
        }];
    }
    return _bottomLine;
}



-(void)tapEvent
{
    self.sectionGroupModel.isOpen=!self.sectionGroupModel.isOpen;

    /** 如果代理响应了代理方法，就要调用这个方法*/
    if ([self.delegate respondsToSelector:@selector(didSelectTableViewHeaderFooterView)]) {
        [self.delegate didSelectTableViewHeaderFooterView];
    }
}



- (void)layoutSubviews
{
    [super layoutSubviews];

}

#pragma mark - groupModel
-(void)setSectionGroupModel:(SectionGroupModel *)sectionGroupModel
{
    _sectionGroupModel=sectionGroupModel;

    self.nameLabel.text=sectionGroupModel.name;
}

@end

